﻿using System;
using XSTDZ.ERP.Application.DataContracts;
using System.Collections.Generic;

namespace XSTDZ.ERP.Application
{
    /// <summary>
    /// 发货服务
    /// </summary>
    public interface IProductDeliveryBillService
    {
        #region 发货订单
        /// <summary>
        /// 添加发货任务单据
        /// </summary>
        /// <param name="productDeliveryBillDto"></param>
        Guid AddProductDeliveryBill(ProductDeliveryBillDto productDeliveryBillDto);
        /// <summary>
        /// 添加发货任务单据
        /// </summary>
        /// <param name="productDeliveryBillDto"></param>
        Guid AddProductDeliveryBill(ProductDeliveryBillDto productDeliveryBillDto, IEnumerable<ProductDeliveryBillDetailDto> productDeliveryBillDetailDtos, bool isValidateStock);
        /// <summary>
        /// 添加发货任务单据
        /// </summary>
        /// <param name="productDeliveryBillDto"></param>
        Guid AddProductDeliveryBill(Guid productDeliveryBillId, IEnumerable<ProductDeliveryBillDetailDto> productDeliveryBillDetailDtos);
        void UpdateProductDeliveryBill(ProductDeliveryBillDto productDeliveryBillDto);
        void UpdateProductDeliveryBill(Guid productDeliveryBillId, IEnumerable<ProductDeliveryBillDetailDto> productDeliveryBillDetailDtos);
        Guid UpdateProductDeliveryBill(ProductDeliveryBillDto productDeliveryBillDto, IEnumerable<ProductDeliveryBillDetailDto> productDeliveryBillDetailDtos,bool isValidateStock);

        void ConvertProductDeliveryBillDeleteState(Guid productDeliveryBillId);
        void ConvertProductDeliveryBillDeleteState(Guid productDeliveryBillId, IEnumerable<Guid> profitAndLossBillDetailIds);

        ProductDeliveryBillDto GetProductDeliveryBill(Guid productDeliveryBillId);
        /// <summary>
        /// 获取发货信息
        /// </summary>
        /// <param name="pageIndex">页索引(从1开始)</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="isDeleted">是否删除(默认：false)</param>
        /// <param name="isAudited">是否确认(默认：false)</param>
        /// <returns>发货信息列表</returns>
        IEnumerable<ProductDeliveryBillDto> GetProductDeliveryBills(int pageIndex, int pageSize,bool?isDeleted,bool? isAudited);

        IEnumerable<ProductDeliveryBillDto> GetProductDeliveryBills(IEnumerable<Guid> productDeliveryBillIds);

        //把生成的发货数据更新至库存，会影响库存
        void UpdateToStock(Guid productDeliveryBillId, IEnumerable<Guid> productDeliveryBillDetailIds);

        /// <summary>
        /// 发货提交
        /// </summary>
        /// <param name="billIds">业务单据ID集合</param>
        /// <param name="userId">确认用户ID</param>
        void ConfirmProductDelivery(IList<Guid> billIds, Guid userId);
        /// <summary>
        /// 厂里发货提交（不需要更新库存）
        /// </summary>
        /// <param name="billIds"></param>
        /// <param name="userId"></param>
        void ConfirmProductDeliveryNoStock(IList<Guid> billIds, Guid userId);
        #endregion
        #region 发货订单明细
        void AddProductDeliveryBillDetail(Guid productInBillId, ProductDeliveryBillDetailDto productCheckBillDetailDto);
        void UpdateProductDeliveryBillDetail(Guid productInBillId, IEnumerable<ProductDeliveryBillDetailDto> productDeliveryBillDetailDtos);
        ProductDeliveryBillDetailDto GetProductDeliveryBillDetail(Guid productCheckBillDetailId);
        IEnumerable<ProductDeliveryBillDetailDto> GetProductDeliveryBillDetails(Guid productDeliveryBillId);

        #endregion
        #region 其它
        /// <summary>
        /// 获得当前发货单单号的最大单号
        /// </summary>
        /// <returns></returns>
        string GetMaxBillNo();
        #endregion
        #region 导入确认的单据到入库单
        /// <summary>
        /// 导入确认的单据到入库单(这个设计有问题，暂时先这样)
        /// </summary>
        /// <param name="deliveryIds">确认的出库单ID集合</param>
        /// <param name="createId">操作用户</param>
        /// <param name="minProductInNo">当前最大的单号</param>
        /// <param name="len">单号最后部分的位数</param>
        /// <returns></returns>
        void Audit(IList<Guid> deliveryIds, Guid createId, string minProductInNo, int len);
        /// <summary>
        /// 打回
        /// </summary>
        /// <param name="deliveryIds"></param>
        /// <param name="createId"></param>
        /// <param name="minProductInNo"></param>
        /// <param name="len"></param>
        void UnAudit(IList<Guid> deliveryIds, Guid createId, string minProductInNo, int len);
        #endregion
     
        Dictionary<ProductDeliveryBillDto, IEnumerable<ProductDeliveryBillDetailDto>> GetBillAndDetails(Guid outBillId);
    }
}
